package DFS;

import java.util.Scanner;

/**
 * create by Sun
 * 2018/8/21
 * todo 全队列
 */
public class quanduilie {
    private static int[] a=new int[1900];
    private static int[] b=new int[1000];
    private static int step;
    private static int n;


    static void dfs(int step){
        if(step>n){
            for(int i=1;i<=n;i++){
                System.out.print(a[i]+" ");
            }
            System.out.println();
        }


        for(int i=1;i<=n;i++){
            if(b[i]!=1){
               a[step]=i;
               b[i]=1;
               dfs(step+1);
               b[i]=0;
            }
        }
    }
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);

        n=sc.nextInt();

        dfs(1);
    }
}
